<?php

namespace App\Http\Resources;

use App\Helpers\BaseResource;

class UserListened extends BaseResource
{
    public function toArray($request)
    {
        return $this->filterFields([
            'id' => hashid_encode($this->id),
            'type' => $this->item_type,
            'time' => $this->updated_at->diffForHumans(),
            'item' => $this->whenLoaded('item', function () {
                switch ($this->item_type) {
                    case \App\Models\DocPage::class:
                        $docPageRes = DocPage::make($this->item)->relate($this->RelateWithoutFields);
                        $docPageRes = $this->get_relate_data('doc_page', $docPageRes);
                        return $docPageRes;
                        break;
                }
            })
        ]);
    }
}
